<script>
$(function(){
	<!--datepick-->
	$( "#from" ).datepicker({
		monthNamesShort: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
		isBE: true,
		autoConversionField: true,
		defaultDate: "+1w",
		changeYear:true,
		changeMonth: true,
		dateFormat:'dd/mm/yy',
		onSelect: function( selectedDate ) {
			//$( "#to" ).datepicker( "option", "minDate", selectedDate );
		}
	});
	$( "#to" ).datepicker({
		monthNamesShort: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
		defaultDate: "+1w",
		isBE: true,
		autoConversionField: true,
		changeYear:true,
		changeMonth: true,
		dateFormat:'dd/mm/yy',
		onSelect: function( selectedDate ) {
			//$( "#from" ).datepicker( "option", "maxDate", selectedDate );
			$('#report').html('<img style=\'margin-top:100px;\' src=\'backend/images/loading.gif\' align="absmiddle"/>');  
			$.post(
				'member_report_ajax.php',
				{from:$('#from').val(),to:$('#to').val()},
				function(data){
					$('#ui-tabs-1').html(data).hide().fadeIn('fast');
				}
			);	
		}
	});
	
	$("a[rel='aj']").live('click', function(eve){
		$('#ui-tabs-1').html('<div align="center" style="margin:5%;"><img src="images/loading.gif"/></div>');
		var the_link = $(this).attr("href") + '&type=ajax';
		eve.preventDefault();
		$.get(the_link)
		.success(function (data){
			$('#ui-tabs-1').html(data).hide().fadeIn('slow');
		});
	
	});
});
</script>
<? 
@session_start(); 
include("backend/include/db_connect.php"); 
connect();
$sql="SET CHARACTER SET UTF8";   
query($sql); 
include "try_session_login.php";

$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end=20;

$limit_start = ($page-1)*$limit_end;

$send = "type=".$_GET['type'];

$sql = "select * from tb_report where membershipId = '".$_SESSION['username_log']."'";
if($_POST['to']){
	$start = explode('/',$_POST['from']);
	$date_start = mktime(0,0,0,$start[1],$start[0],$start[2]);
	$end = explode('/',$_POST['to']);
	$date_end = mktime(0,0,0,$end[1],$end[0],$end[2]);
	$sql.= " and sendDate between '".$date_start."' and '".$date_end."'";	
}
$sql .= " order by sendDate";
$qr=select($sql. " LIMIT " . $limit_start. "," . $limit_end); 
$total=count($qr);
$rows = mysql_num_rows(mysql_query($sql));
$i=0;

?>
<div>
    <label for="from">ค้นหาตามช่วงเวลา</label>
    <input type="text" id="from" name="from" value="<?=$_POST['from'];?>"/>
    <label for="to">ถึง</label>
    <input type="text" id="to" name="to" value="<?=$_POST['to'];?>"/>
</div>
<table width="100%" border="1" align="center" cellpadding="1" cellspacing="0" style="border-collapse:collapse;" id="tbl_content">
  <tr class="ui-widget-header">
    <td align="center" >ลำดับ</td>
    <td align="center"  >วันแจ้งงาน</td>
    <td align="center"  >วันคุ้มครอง</td>
    <td align="center"  >เลขรับแจ้ง</td>
    <td align="center"  >บริษัท</td>
    <td align="center"  >ประเภท</td>
    <td align="center"  >รหัสจัดส่ง<br />ไปรษณีย์</td>
    <td align="center"  >ชื่อผู้เอาประกัน</td>
    <td align="center"  >ทุนเอาประกัน</td>
    <td align="center"  >เบี้ยสุทธิ</td>
    <td align="center"  >เบี้ยรวม</td>
    <td width="34" align="center" >#</td>
  </tr>
  <?php
  
if($total > 0){ 
	while($i<count($qr)){ 
	$rs=$qr[$i];
	if($bg=='#ffffff'){$bg='#f2f2f2';}else{$bg='#ffffff';}
	if($rs[active]==0){$rs[active]="offline"; $text='<span style="color:black;">ยังไม่ติดต่อ</span>'; }else{$rs['active']="online"; $text='<span style="color:green;">ติดต่อแล้ว</span>';} 
?>
  <tr  bgcolor="<?=$bg?>"  onmouseout="this.className='show'" class="show" onmouseover="this.className='ui-state-error','show'" id="list<?=$rs['id']?>">
    <td align="center" ><?=$limit_start+$i+1;?></td>
    <td align="center"><?=date("d/m/Y",trim($rs['sendDate']));?></td>
    <td align="center"><?=date("d/m/Y",trim($rs['protectionStart']));?></td>
    <td align="center"><? echo $rs['receiptNo'] ?></td>
    <td align="center"><?=$rs['company']?></td>
    <td align="center"><?=$rs['insureType']?></td>
    <td align="center" valign="middle"><?=$rs['postcode']?></td>
    <td align="center" valign="middle"><?=$rs['customerName']?></td>
    <td align="center" valign="middle"><?=$rs['insureBudget']?></td>
    <td align="center" valign="middle"><?=$rs['insureNet']?></td>
    <td align="center" valign="middle"><?=$rs['insureTotal']?></td>
    <td align="center" valign="middle">
     	<ul id="icons" class="ui-widget ui-helper-clearfix">
           
             <?php if($rs['report_doc']){ ?>
            <li class="ui-state-default ui-corner-all" title="ดูกรมธรรม์" onclick="window.open('upload/<?=$rs['report_doc']?>');"><span class="ui-icon ui-icon-zoomin"></span></li>
            <?php } ?>
         </ul>
     </td>
  </tr>
  <?php 
  $i++;
	}//end while//
}//end if($total > 0)//
  ?>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
	<?php if(($rows/$limit_end) > 1){ 
		 echo "\n<div align=\"right\" class=\"pagination\">" . page_ajax($page, $limit_end, 4, $rows, $send,"mynavic","mynavi",$target,'member_report_ajax.php') . " </div>";
	}
	?></td>
  </tr>
</table>